Microcontrollers in an embedded system typically include a central processing unit (CPU), non-volatile memory (such as EEPROM or flash memory), interfaces, random access memory (RAM), and other peripherals integrated onto a single integrated circuit. Hence, the number of chips, wires, and space needed is reduced compared to using separate chips. In addition, unlike general purpose microprocessors, microcontrollers are typically designed to carry out specific functions which increases their cost-effectiveness.
However, microcontrollers are vulnerable to data corruption such as corruption due to code run-away. Code run-away can be caused by faulty code, operating the Micro-Controller Unit (MCU) outside its specification or by a major electromagnetic interference (EMI) or electrical noise event. By definition, it is not well defined what will happen during code run-away, but it is caused by the out-of-specification operating environment effectively corrupting the program counter resulting in the MCU behaving unpredictably. A corrupted program counter could lead to a jump to programming code that performs the flash erase or write operation, resulting in accidental corruption of flash memory data that contains application code. Once the application code is corrupted, it is typically not possible to recover until the correct application code is programmed again.
For the reasons stated above, and for other reasons stated below which will become apparent to those skilled in the art upon reading and understanding the present specification, there is a need in the art for a system and method to detect and recover from flash corruption.